package org.cwnuit.course.dao;

import java.sql.SQLException;
import java.util.List;

import org.cwnuit.course.domain.Course;
import org.cwnuit.course.util.IbatisSqlConfig;

import com.ibatis.sqlmap.client.SqlMapClient;

/**
 * 学科管理DAO
 * @author john
 */
public class CourseDAO{
	
	/**
	 * 根据学科ID获取学科信息
	 * @param objectid
	 * @return
	 */
	public Course getCourse(Integer objectid) {
		SqlMapClient sqlMap = IbatisSqlConfig.getSqlMapInstance();
		Course course = null;
		try {
			course = (Course) sqlMap.queryForObject("Course.getCourse",objectid);
		} catch (SQLException e) {
			e.printStackTrace();
		}
		return course;
	}

	/**
	 * 获取全部学科信息
	 * @return
	 */
	@SuppressWarnings("unchecked")
	public List<Course> listCourse() {
		SqlMapClient sqlMap = IbatisSqlConfig.getSqlMapInstance();
		List<Course> courseList = null;
		try {
			courseList = (List<Course>) sqlMap.queryForList("Course.listCourse");
		} catch (SQLException e) {
			e.printStackTrace();
		}
		return courseList;
	}
	
	/**
	 * 添加学科信息
	 * @param Course
	 * @return
	 */
	public boolean insertCourse(Course course) {
		SqlMapClient sqlMap = IbatisSqlConfig.getSqlMapInstance();
		try {
			sqlMap.insert("Course.insertCourse", course);
			return true;
		} catch (SQLException e) {
			e.printStackTrace();
		}
		return false;
	}
	
	/**
	 * 更新学科信息
	 * @param Course
	 * @return
	 */
	public boolean updateCourse(Course course) {
		SqlMapClient sqlMap = IbatisSqlConfig.getSqlMapInstance();
		try {
			sqlMap.update("Course.updateCourse", course);
			return true;
		} catch (SQLException e) {
			e.printStackTrace();
		}
		return false;
	}
	
	/**
	 * 删除学科信息
	 * @param objectid
	 * @return
	 */
	public boolean deleteCourse(Course course) {
		SqlMapClient sqlMap = IbatisSqlConfig.getSqlMapInstance();
		try {
			sqlMap.delete("Course.deleteCourse", course);
			return true;
		} catch (SQLException e) {
			e.printStackTrace();
		}
		return false;
	}
}
